using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Text;
using System.Windows.Forms;
public class UpdateFile
{
	public static void smethod_0(string string_0, string string_1, string string_2, int int_0)
	{
		string currentDirectory = Directory.GetCurrentDirectory();
		if (!Directory.Exists(currentDirectory + "\\config"))
		{
			Directory.CreateDirectory(currentDirectory + "\\config");
		}
		HttpService httpService = new HttpService();
		int num = int.Parse(httpService.post(string_0, "type=softwarever&softwarename=" + string_1));
		if (num > int_0)
		{
			UpdateForm updateForm = new UpdateForm();
			updateForm.Show();
			UpdateFile.smethod_1("http://www.zhezhehui.cn/s/" + string_2 + ".exe", currentDirectory + "\\config\\" + string_2 + ".exe", updateForm.progressBar1, updateForm.label1);
			updateForm.Close();
			string text = currentDirectory + "\\config\\update.cmd";
			FileStream fileStream = new FileStream(text, FileMode.Create);
			StreamWriter streamWriter = new StreamWriter(fileStream, Encoding.GetEncoding("GB2312"));
			streamWriter.WriteLine("taskkill /f /im " + string_2 + ".exe");
			streamWriter.WriteLine(string.Concat(new string[]
			{
				"copy \"",
				currentDirectory,
				"\\config\\",
				string_2,
				".exe\" \"",
				currentDirectory,
				"\\",
				string_2,
				".exe\""
			}));
			streamWriter.WriteLine(string.Concat(new string[]
			{
				"del \"",
				currentDirectory,
				"\\config\\",
				string_2,
				".exe\""
			}));
			streamWriter.WriteLine("ping -n 2 127.1>nul");
			streamWriter.WriteLine(string.Concat(new string[]
			{
				"start \"\" \"",
				currentDirectory,
				"\\",
				string_2,
				".exe\""
			}));
			streamWriter.WriteLine("exit");
			streamWriter.Flush();
			streamWriter.Flush();
			streamWriter.Close();
			streamWriter.Dispose();
			fileStream.Close();
			fileStream.Dispose();
			Process.Start("\"" + text + "\"");
		}
		else
		{
			if (int_0 > num)
			{
				httpService.post(string_0, string.Concat(new object[]
				{
					"type=updsoftwarever&softwarename=",
					string_1,
					"&version=",
					int_0
				}));
			}
		}
		if (Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Length > 1)
		{
			MessageBox.Show("程序已经运行！", "消息", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
			Environment.Exit(Environment.ExitCode);
		}
	}
	public static void smethod_1(string string_0, string string_1, ProgressBar progressBar_0, Label label_0)
	{
		try
		{
			HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(string_0);
			HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
			long contentLength = httpWebResponse.ContentLength;
			if (progressBar_0 != null)
			{
				progressBar_0.Maximum = (int)contentLength;
			}
			Stream responseStream = httpWebResponse.GetResponseStream();
			Stream stream = new FileStream(string_1, FileMode.Create);
			long num = 0L;
			byte[] array = new byte[1024];
			int i = responseStream.Read(array, 0, array.Length);
			while (i > 0)
			{
				num = (long)i + num;
				Application.DoEvents();
				stream.Write(array, 0, i);
				if (progressBar_0 != null)
				{
					progressBar_0.Value = (int)num;
				}
				i = responseStream.Read(array, 0, array.Length);
				label_0.Text = "当前下载进度" + ((int)((float)num / (float)contentLength * 100f)).ToString() + "%";
				Application.DoEvents();
			}
			stream.Close();
			responseStream.Close();
		}
		catch (Exception)
		{
			throw;
		}
	}
}
